/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle <lylechen2014@gmial.com>
 * @since : 2014-09-30 11:02:27
 * @filename : static/logic/nmm/src/views/myProfilePersonalInfo.js
 * @version : 
 * @description : 
 */

define(function(require, exports, module){

    var myProfilePersonalInfoView,userObj,
        mId = 'myProfilePersonalInfo',reRender = false,menuName = 'myProfilePersonalInfo',
        imglazyload = require('{component}imglazyload/zepto.imglazyload'),
        panel = require('{component}panel/zepto.panel'),
        tplN = require('{view}userNav.tpl'),
        tplS = require('{view}select.tpl'),
        tpl = require('{view}myProfilePersonalInfo.tpl');

    myProfilePersonalInfoView = Backbone.View.extend({

        template: _.template(tpl),
        templateS: _.template(tplS),
        templateN: _.template(tplN),

        bindEvt : function() {
            var tthis = this,dom = $('#'+mId);
           
            dom.find('.back').on('tap',function(e){
                window.location.href = '#myProfile/whole/custom2'; 
            });

            dom.find('.save').on('tap',function(e){
                var usr_id = userObj.account.usr_id;
                var obj = {
                    education: dom.find('#education').val(),
                    language: dom.find('#language').val(),
                    occupation: dom.find('#occupation').val(),
                    political_beliefs: dom.find('#political').val(),
                    religion: dom.find('#religion').val()
                };

                var callback = function(){
                    userObj.detail.personalinfo.education = obj.education;
                    userObj.detail.personalinfo.language = obj.language;
                    userObj.detail.personalinfo.occupation = obj.occupation;
                    userObj.detail.personalinfo.political = obj.political_beliefs;
                    userObj.detail.personalinfo.religion = obj.religion;
                    share.cacheUserInfo(usr_id,userObj);
                    window.location.href = '#myProfile/whole/custom2'; 
                }
                share.updateProfile(usr_id,callback,obj);
            });

        },      

        render: function (obj) {
            if (!share.checkPermission(true)){return;};  
            userObj = share.getObjStorage(share.userInfo().usr_id);
            if ($('#'+mId).length < 1) { 
                $('body').append(this.template(lang));

                this.bindEvt(); 
            } else {
                $('#'+mId).css('display','block');
            }

            share.panel(panel,this.templateN,mId,menuName);
            this.educationRender();
            this.languageRender();
            this.occupationRender();
            this.politicalRender();
            this.religionRender(); 
        },

        educationRender : function() {
            var select = share.getLocalStorage('ms_education');
            $('#'+mId).find('#education').html(this.templateS({obj : select, value : userObj.detail.personalinfo.education}));
        },

        languageRender : function() {
            var select = share.getLocalStorage('ms_language');
            $('#'+mId).find('#language').html(this.templateS({obj : select, value : userObj.detail.personalinfo.language}));
        },

        occupationRender : function() {
            var select = share.getLocalStorage('ms_occupation');
            $('#'+mId).find('#occupation').html(this.templateS({obj : select, value : userObj.detail.personalinfo.occupation}));
        },

        politicalRender : function() {
            var select = share.getLocalStorage('ms_political_beliefs');
            $('#'+mId).find('#political').html(this.templateS({obj : select, value : userObj.detail.personalinfo.political}));
        },

        religionRender : function() {
            var select = share.getLocalStorage('ms_religion');
            $('#'+mId).find('#religion').html(this.templateS({obj : select, value : userObj.detail.personalinfo.religion}));
        }
	});
	module.exports = myProfilePersonalInfoView;
})

